function t(t) {
    this.selfOpenId = "", this.ctx = t, this.left = 0, this.top = 0, this.width = 1e3, 
    this.height = 1e3, this.sortedRankData = [], this.myInfo = {}, this.opened = !1, 
    this.scoreFont = "arial";
}

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = t;

var e = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("./utils.js"));

t.prototype.logicHandle = function(t) {
    var e = this;
    this.opened = !0, wx.getFriendCloudStorage({
        shareTicket: t.shareTicket,
        keyList: [ "score" ],
        success: function(a) {
            e.sortRankList(a.data), e.drawRankList(t);
        }
    });
}, t.prototype.setOpenId = function(t) {
    if (this.selfOpenId = t, this.opened) {
        if (this.sortedRankData.length <= 0) return;
        this.getMyInfo(), this.drawRankList();
    }
}, t.prototype.sortRankList = function(t) {
    var a = e.default.transRankData(t);
    this.sortedRankData = e.default.quickSortByScore(a);
}, t.prototype.getMyInfo = function() {
    for (var t = 0; t < this.sortedRankData.length; t++) if (this.selfOpenId === this.sortedRankData[t].openId) {
        this.myInfo.rank = t + 1, this.myInfo.avatarUrl = this.sortedRankData[t].avatarUrl, 
        this.myInfo.nickname = this.sortedRankData[t].nickname, this.myInfo.score = this.sortedRankData[t].score;
        break;
    }
}, t.prototype.drawRankList = function(t) {
    this.getMyInfo();
    this.ctx;
    t && t.left && (this.left = t.left), t && t.top && (this.top = t.top), t && t.width && (this.width = t.width), 
    t && t.height && (this.height = t.height), this.sortedRankData.length <= 0 || this.drawSinglePage();
}, t.prototype.drawSinglePage = function() {
    if ("" !== this.selfOpenId) {
        this.ctx.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight);
        var t, a = this.myInfo.rank;
        a - 1 > 0 && ((t = this.sortedRankData[a - 2]).rank = a - 1, this.drawElement(0, t, this.left, this.top, 312, 100)), 
        this.drawElement(1, this.myInfo, this.left + 312, this.top, 312, 100), a + 1 <= this.sortedRankData.length && ((t = this.sortedRankData[a]).rank = a + 1, 
        this.drawElement(2, t, this.left + 624, this.top, 312, 100));
    }
}, t.prototype.closedClear = function() {
    this.opened = !1;
    var t = this.sortedRankData.length;
    if (!(t <= 0)) {
        var a = this.ctx, i = this.myInfo.rank - 2;
        i < 0 && (i = this.myInfo.rank - 1);
        var s = this.myInfo.rank;
        s >= t && (s = t - 1);
        for (var n = i; n < s; n++) {
            var o = this.sortedRankData[n];
            o.img && (o.img.onload = null);
        }
        a.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight);
    }
}, t.prototype.drawElement = function(t, e, a, i, s, n) {
    var o = 140, r = 1 === t ? "85px " + this.scoreFont : "50px " + this.scoreFont, h = 140, d = 140, l = "50px " + this.scoreFont, f = this.ctx;
    if (e.img) e.loaded || (e.img.onload = function() {
        f.drawImage(e.img, a + 101, i + 203, 110, 110), e.loaded = !0;
    }); else {
        var c = wx.createImage();
        c.src = e.avatarUrl, e.img = c, c.onload = function() {
            f.drawImage(e.img, a + 101, i + 203, 110, 110), e.loaded = !0;
        };
    }
    var p = 1 === t ? "#00d2cb" : "#fff";
    f.fillStyle = p, f.font = r, o = (312 - f.measureText((t + 1).toString()).width) / 2, 
    f.fillText(e.rank, a + o, i + 160), f.drawImage(e.img, a + 101, i + 203, 110, 110), 
    f.font = "35px Arial", f.fillStyle = "rgba(150,150,150,0.5)", h = (312 - f.measureText(e.nickname).width) / 2, 
    f.fillText(e.nickname, a + h, i + 392), f.font = l, f.fillStyle = "#fff", d = (312 - f.measureText(e.score).width) / 2, 
    f.fillText(e.score, a + d, i + 495);
};